/**
 * 
 */
package jmath.io;

import javax.swing.JTextPane;
import org.springframework.util.Assert;

/**
 * @author timon
 *
 */
public class JMathScripter {	
	
	private JTextPane scriptPane;	

	private JTextPane getScriptPane() {
		Assert.notNull(scriptPane);
		return scriptPane;
	}

	public void setScriptPane(JTextPane scriptPane) {
		this.scriptPane = scriptPane;
	}
	
	public String readScript(){
		String selectedScript=getScriptPane().getSelectedText();
		if(selectedScript!=null && selectedScript.length()>0){
			return selectedScript;
		}
		return readAllScript();
	}
	
	public String readAllScript(){		
		return getScriptPane().getText();
	}
	
	public void writeScript(String script){
		getScriptPane().setText(script);
	}
	
}
